Ext.define('PJ.view.messagemanagement.ReplyEdit', {
	extend: 'AM.default.DefaultWindowForm',
	alias: ['widget.replyEdit'],
	requires: ['AM.default.DefaultDateField', 
	           'AM.default.DateTime',
	           'AM.default.jsonp.DefaultSubmitJsonp',
	           'PJ.view.messagemanagement.RestoredMessageList',
	           'AM.default.DefaultDateField'],

	modal: true,// 开启不允许点击其他组件
	frame: true,
	notEdit: true,
	width: 520,
	height:540,
	layout: 'form',
	isSame: false,
	autoHeight: true,

	initComponent: function(){
    	var me = this;
    	var bt = '<span style="color:red;">*</span>';
    	me.items= [{
    		defaults: {
    			labelAlign: 'right',
    			labelWidth: 80,
    			columnWidth: 1,
    			padding:"5 0 0 0",
    			readOnly:me.isView
    		},
    		border: false,
    		xtype: "container",
    		width: 495,
    		layout: 'column',
    		items: [{
            	xtype: 'textarea',
                fieldLabel: me.text == "接收通知"?'发送人':"接收人",
                name:  me.text=="接收通知"?"userName":"receiveUserNames",
	            readOnly:true,
    			height: 40
            },{
            	xtype: 'textfield',
                fieldLabel: "通知类型",
                name:"newsCode",
//                name: me.text=="接收通知"?"newsTypeCode":"newsType",
	            readOnly:true
            },{
            	xtype: 'textfield',
                fieldLabel: "培训班名称",
                name: 'specialName',
	            readOnly:true,
	            columnWidth:1
            },{
    			xtype: 'textarea',
    			fieldLabel: '发送内容',
//    			name: me.text=="接收通知"?"newsValue":"replyValue",
    			name:"newsValue",
    			readOnly:true,
    			height: 50
    		},{
    			xtype: 'restoredMessageList',
    			height: 280
    		},{
    			xtype: 'textarea',
    			fieldLabel: bt + '回复',
    			labelWidth: 35,
    			maxLength: 200,
    			name: 'replyValue',
    			allowBlank: false,
    			height: 50
    		}]
    	}];
    	this.buttons = [{
            text: '确定',
            handler: function(button, event){
                var win = button.up('window');
                win.sub();
            }
        }, {
            text: '关闭',
            scope: this,
            handler: function(button, event){
                var win = button.up('window');
                win.grid.store.load();
                win.close();
            }
        }];
		this.callParent(arguments);
	},
    sub:function(){
		var win = this;
		var form = win.down('form');
		var baseForm = form.getForm();
		if (!baseForm.isValid()) {
			return;
		}
		var url = win.grid.store.replyUrl;
		var newsUserLink = win.newsUserLink;
		var newsId = win.newsId;
		var replyValue = baseForm.findField("replyValue")
		if(gj_onlineLearning_constant.loadType == "jsonp"){
			baseForm.doAction('submitJsonp',{
				url: url,
				params:{
					newsUserLink:newsUserLink,
					lookState:1,
					newsId:newsId
				},
				success: function(f, action){
					if (action.result.success) {
						Ext.Msg.alert('通知', "操作成功!", function(){
							win.down("restoredMessageList").store.load();
							replyValue.setValue("");
//							win.close();
						});
					}else{
						Ext.Msg.alert('通知', action.result.msg||"系统出错,请联系管理员!", function(){
							win.close();
						});
					}
				},
				failure: function(f, action){
					if (action.result) {
						Ext.Msg.alert('错误', action.result.msg||"系统出错,请联系管理员!");
					}
					else {
						Ext.Msg.alert('错误', action.result.msg||"系统出错,请联系管理员!");
					}
				}
			});
		}else{
			baseForm.submit({
				url: url,
				params:{
					newsUserLink:newsUserLink,
					lookState:1,
					newsId:newsId
				},
				success: function(f, action){
					if (action.result.success) {
						Ext.Msg.alert('通知', "操作成功!", function(){
							win.down("restoredMessageList").store.load();
							replyValue.setValue("");
						});
					}else{
						Ext.Msg.alert('通知', action.result.msg||"系统出错,请联系管理员!", function(){
							win.close();
						});
					}
				},
				failure: function(f, action){
					if (action.result) {
						Ext.Msg.alert('错误', action.result.msg||"系统出错,请联系管理员!");
					}
					else {
						Ext.Msg.alert('错误', "系统出错,请联系管理员!");
					}
				}
			});
		}
	
    }
});